import retry from 'promise-retry';

async function getRetryOptions(retries = 3) {
  const retryOptions = {
    retries,
    factor: 2,
    minTimeout: 1 * 1000,
    randomize: true
  };

  return retryOptions;
}

export async function promiseRetry(fn, retries = 3) {
  const retryOptions = await getRetryOptions(retries);
  return retry(fn, retryOptions);
}
